package com.example.menhoo.toollibrary.common.io;

import android.content.Context;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

/**
 * Created by yanglei on 16/8/16.
 */
public class ReadProperties {
    private int RID = -1;
    private Context context=null;
    Properties properties = null;

    public ReadProperties(Context context,int R_raw_id) throws IOException {
        RID = R_raw_id;
        this.context = context;
        InputStream is = this.context.getResources().openRawResource(RID);
        properties = new Properties();
        properties.load(is);
    }
    public String getValue(String key){
        if(properties!=null){
            String result = properties.getProperty(key, null);
            try {
                result = new String(result.getBytes("ISO-8859-1"),"UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            return result;
        }
        return null;
    }

    public Properties getProperties() {
        return properties;
    }
}
